import Banner from "../Banner";
import { 头盔, 手枪, 防弹衣, 突击步枪, 冲锋枪, 射手步枪, 栓动步枪, 轻机枪, 霰弹枪, 卡宾枪, 投掷物, 子弹, 药品, 食物, ItemData, } from "../Datas/Data";
import { Constant, ItemType } from "../Framework/Const/Constant";
import AudioManager from "../Framework/Managers/AudioManager";
import { BundleManager, Bundles } from "../Framework/Managers/BundleManager";
import { DataManager } from "../Framework/Managers/DataManager";
import { PoolManager } from "../Framework/Managers/PoolManager";
import { UIManager } from "../Framework/Managers/UIManager";
import NodeUtil from "../Framework/Utils/NodeUtil";
import { ResourceUtil } from "../Framework/Utils/ResourceUtil";
import { ZTool } from "../Framework/Utils/ZTool";
import SpecialSkinItem from "./SpecialSkinItem";

const { ccclass, property } = cc._decorator;

@ccclass
export default class SpecialSkinDetailPanel extends cc.Component {
    Item: cc.Sprite = null;
    Mask: cc.Sprite = null;
    Name: cc.Label = null;
    data: ItemData = null;

    protected onLoad(): void {
        this.Item = NodeUtil.GetComponent("Item", this.node, cc.Sprite);
        this.Mask = NodeUtil.GetComponent("Mask", this.node, cc.Sprite);
        this.Name = NodeUtil.GetComponent("Name", this.node, cc.Label);
    }

    Show(data: ItemData) {
        this.data = data;
        Banner.Instance.ShowCustomAd();

        this.Name.string = `${data.Name}`;
        BundleManager.LoadSpriteFrame(Bundles.Item, `GunBG_${data.Name}`).then((sf: cc.SpriteFrame) => {
            this.Mask.spriteFrame = sf;
        });

        BundleManager.LoadSpriteFrame(Bundles.Item, `${data.Type}_${data.Name}`).then((sf: cc.SpriteFrame) => {
            this.Item.spriteFrame = sf;
        });

        cc.Tween.stopAllByTarget(this.Item.node);

        let scale = 6;
        if (data.Name == `G18C-矩形几何`) scale = 4;

        this.Item.node.setScale(scale);

        cc.tween(this.Item.node).to(1, { scale: scale + 1 }).to(1, { scale: scale }).union().repeatForever().start();
        cc.tween(this.Item.node).to(1, { angle: 6 }).to(1, { angle: -6 }).union().repeatForever().start();
    }

    OnBuyButtonClick() {
        AudioManager.PlayAudio(Constant.Audio.ButtonClick);
        Banner.Instance.ShowVideoAd(() => {
            UIManager.Instance.HidePanel(Constant.Panel.SpecialSkinDetailPanel);
            DataManager.AddPlayerItem(ZTool.DeepCopy(this.data));
            UIManager.Instance.ShowPanel(Constant.Panel.RewardPanel, [this.data])
        });
    }

    OnReturnButtonClick() {
        AudioManager.PlayAudio(Constant.Audio.ButtonClick);
        UIManager.Instance.HidePanel(Constant.Panel.SpecialSkinDetailPanel);
    }
}